package com.itheima.file;

import java.io.File;
import java.util.HashMap;

public class FileDemo06 {
    public static void main(String[] args) {
        File file = new File("C:\\Users\\l7851\\Desktop\\JAVA相关");
        HashMap<String,Integer> hm = new HashMap<>();
        getFile(hm,file);
        System.out.println(hm);
    }

    private static void getFile(HashMap<String, Integer> hm, File file) {
        File[] files = file.listFiles();
        for (File file1 : files) {
            if (file1.isFile()) {
                String[] split = file1.getName().split("\\.");
                if (hm.containsKey(split[split.length - 1])) {
                    Integer integer = hm.get(split[split.length - 1]);
                    hm.put(split[split.length - 1], ++integer);
                } else {
                    hm.put(split[split.length - 1], 1);
                }
            }else {
                getFile(hm,file1);
            }
        }
    }
}
